package list;

public class HeBingYouXu {
    public static void main(String[] args) {
        Node head1 = new Node(1);
        head1.next = new Node(3);
        head1.next.next = new Node(5);
        head1.next.next.next = new Node(7);
        head1.next.next.next.next = new Node(8);



        Node head2 = new Node(2);
        head2.next = new Node(4);
        head2.next.next = new Node(6);
        head2.next.next.next = new Node(9);
        head2.next.next.next.next = new Node(10);



        Node n1 = head1;
        Node n2 = head2;
        Node qq = new Node(0);
        Node n =qq;
        while (n1!=null&& n2 != null){
            if(n1.value>n2.value){
                n.next=new Node(n2.value);
                n = n.next;
                n2 = n2.next;
            }else {
                n.next = new Node(n1.value);
                n = n.next;
                n1 = n1.next;
            }

        }
        while (n1!=null){
            n = new Node(n1.value);
            n1 = n1.next;
            n = n.next;
        }
        while (n2!=null){
            n = new Node(n2.value);
            n2 = n2.next;
            n = n.next;
        }

        Node nn = qq;
        while (nn != null) {
            System.out.println(nn.value);
            nn = nn.next;
        }




















//        int value = head2.value;
//
//        Node temp = head1;
//
//        while (true) {
//            Node address = find1(head1.value,n1);
//            Node newHead = find(value, head2);
//            if (n1.value > newHead.value) {
//                address=newHead;
//            }
//
//            n1=n1.next;
//
//            value = newHead.value;
//        }

//        Node n1 = head1;
//        Node n2 = head2;
//        Node newHead = new Node(0);
//        Node temp = newHead;
//        while (n1 != null && n2 != null) {
//            temp = temp.next;
//            if (n1.value < n2.value) {
//
//            }
//        }

    }

    public static Node find(int value,Node head) {
        Node n = head;
        while (n != null) {
            if (n.value == value) {
                return n;
            }
            n = n.next;
        }
        return null;
    }
    public static Node find1(int value,Node head) {
        Node n = head;
        if (n.value == value){
            return n;
        }
        while (n.next != null) {
            if (n.next.value == value) {
                return n;
            }
            n = n.next;
        }
        return null;
    }

    static class Node {
        private int value;
        private Node prev;
        private Node next;

        public Node(int value) {
            this.value = value;
        }
    }
}
